package com.aspect;


import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component//类注解
@Aspect
public class BusinessAspect {
    //声明公共切入点
    @Pointcut("execution(* com.dao.impl.StudentsDaoImpl.*(..))")
    public void myPointcut() {

    }
    //前置通知
    @Before(value = "myPointcut()")
    public void checkPri() {
        System.out.println("权限的校验...");
    }
    //返回通知
    @AfterReturning(value="myPointcut()")
    public void logger() {
        System.out.println("日志记录...");
    }

    //异常通知
    @AfterThrowing(value="myPointcut()",throwing="e")
    public void afterThrowing(Throwable e) {
        System.out.println("异常抛出通知..."+e.getMessage());
    }
    //最终通知
    @After(value="myPointcut()")
    public void after() {
        System.out.println("最终通知...");
    }

    //环绕通知；
    @Around(value="myPointcut()")
    public Object around(ProceedingJoinPoint joinPoint) {
        Object obj=null;
        try {
            System.out.println("环绕内的前置通知");
            obj = joinPoint.proceed();
            System.out.println("环绕内的后置通知");
        } catch (Throwable e) {
            System.out.println("环绕内的异常抛出通知");
            e.printStackTrace();
        } finally {
            System.out.println("环绕内的最终通知");
        }
        return obj;
    }
}
